package com.ciandt.snippetr

import com.google.appengine.api.datastore.Text
import com.google.appengine.api.datastore.Category
import com.google.appengine.api.users.User

class Snippet implements Serializable {
	
	String name
	Text text
	String language
	Date createdDate = new Date()
	List<Category> tags
	User author
	//String postedFrom
	
	static getInstance(snippet) {
		
		Snippet newSnippet = new Snippet(
			name: snippet.name,
			language: snippet.language,
			text: snippet.text as Text
		);
		
		if (snippet.tags) {
			def tags = []
			snippet.tags.split().each { tag ->
				tags << (tag as Category)
			}
			newSnippet.tags = tags
		}
		
		newSnippet
	}
}